<!doctype html>
<html>
<!-- Copyright 2018-2022 Kiwi Browser -->
<head>
  <title>New Tab</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#ffffff">
  <style>
html {
    height: 100%
}

body {
    background-attachment: fixed !important;
    position: initial!important;
    cursor: default;
    font-family: arial, sans-serif;
    font-size: small;
    margin: 0;
    min-height: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    background: white
}

#ntp-contents {
    height: 100%;
    position: relative;
    z-index: 1;
    width: 98%
}

#logo, #fakebox-container {
    flex-shrink: 0
}

a:-webkit-any-link {
    text-decoration: none !important
}

a:link {
    text-decoration: none !important
}


#attribution {
    bottom: 0;
    color: var(--text-color-light);
    cursor: default;
    display: inline-block;
    font-size: 13px;
    left: auto;
    position: fixed;
    right: 8px;
    text-align: left;
    user-select: none;
    z-index: -1
}


#bookmarks-grid, #fake-bookmarks-grid, #ideas-grid {
    margin: 2%;
    margin-top: 0px;
    position: relative
}

@media (max-width: 450px) {
    #bookmarks-grid, #fake-bookmarks-grid, #ideas-grid {
        min-height: 208px
    }
}

@media (min-width: 450px) {
    #bookmarks-grid, #fake-bookmarks-grid, #ideas-grid {
        min-height: 104px
    }
}

#fake-bookmarks-grid {
    z-index: -99999
}

.grid-item {
    float: left;
    width: 64px;
    font-size: 10px;
    overflow: hidden;
    background: #fff;
    margin: 10px;
    color: #3c3c3c;
    text-align: center;
    z-index: 999999
}

.grid-item a {
    text-decoration: none;
    color: #555
}

.grid-image {
    height: 64px;
    width: 64px;
    object-fit: contain
}

#explore-section {
    padding-bottom: 20px
}

.plus-item a {
    text-decoration: none
}

.plus-item {
    line-height: 30px;
    color: #3c3c3c;
    font-size: 25px;
    text-align: center;
    z-index: 999999;
    color: #777
}

.configure-item a, .configure-item-explore a {
    text-decoration: none
}

.configure-item, .configure-item-explore {
    font-size: 21px;
    font-weight: 450;
    z-index: 999999;
    color: #777;
    float: left;
    padding-left: 12px
}

.close-item a {
    text-decoration: none;
    z-index: 9999999
}

.close-item {
    font-size: 21px;
    font-weight: 450;
    z-index: 99999999;
    color: #777;
    position: absolute;
    right: 10px
}

.newsImage {
    width: 128px;
    height: 128px;
    object-fit: cover;
    z-index: 9999999;
    border-radius: 6px
}

.newsItem {
    margin: 5px;
    border-radius: 5px;
    border-bottom: 1px solid #efefef;
    padding-bottom: 15px !important;
    font-family: Roboto,RobotoDraft,Helvetica,Arial,sans-serif;
    margin-top: 15px
}

.newsItem a {
    text-decoration: none
}

.newsTitle {
    color: #222;
    padding-right: 148px;
    padding-top: 5px
}

.newsAttribution, .newsTime {
    color: #555;
    font-size: 70%
}

.newsTime {
    position: relative;
    top: 10px
}

#locale, #explore-title {
    font-size: 12px;
    position: relative;
    top: -2px;
    padding-right: 6px
}

.arrow-down {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #ccc;
    position: relative;
    top: 7px
}

.show {
    display: block !important
}

.dropbtn {
    cursor: pointer
}

.dropdown {
    position: relative;
    display: inline-block
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f1f1f1;
    min-width: 160px;
    overflow: auto;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    margin-top: 15px;
    margin-left: 11px;
    height: 300px
}

.dropdown-content a {
    color: black;
    padding: 3px 1px;
    text-decoration: none;
    display: block;
    font-size: 14px
}

.dropdown a:hover {
    background-color: #ddd
}

.localesList {
    line-height: 28px
}

.localesListUnselected {
    list-style-type: circle
}
</style>
  <meta charset="utf-8">
  <meta name="google" value="notranslate">
  <script>
  if (window.chrome.embeddedSearch.newTabPage.isIncognito) document.getElementsByTagName('html')[0].style.backgroundColor='black';
  </script>
</head>
<!-- Remember to update the test HTML files in chrome/test/data/local_ntp/
   whenever making changes to this file.-->
<body>
<script>
if (window.chrome.embeddedSearch.newTabPage.isIncognito) document.body.style.backgroundColor='black';
</script>
<style>
.newsImage {
  opacity: 0;
  visibility: hidden;
}

.ntpOverlay {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: 9999999999;
  background-color: rgba(255,255,255,1);
}
.centeredBlock {
  position: absolute;
  margin: auto;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 90%;
  height: 70%;
  background-color: #efefef;
  border-radius: 26px;
  text-align: center;
  -webkit-box-shadow: 6px 23px 26px -17px rgba(219,219,219,1);
  -moz-box-shadow: 6px 23px 26px -17px rgba(219,219,219,1);
  box-shadow: 6px 23px 26px -17px rgba(219,219,219,1);
  padding-top: 40px;
}
</style>
<script>
function replaceInnerHTML(oldDiv, html) {
    var newDiv = oldDiv.cloneNode(false);
    newDiv.innerHTML = html;
    oldDiv.parentNode.replaceChild(newDiv, oldDiv);
};

function preconnectTo(url) {
  // let's not fb know that we started the browser
  if (url.includes("facebook"))
    return ;
  var hint = document.createElement("link");
  hint.rel = "preconnect";
  hint.href = url;
  document.head.appendChild(hint);
}

function changeThemeColor(targetColor) {
    var metaThemeColor = document.querySelector("meta[name=theme-color]");
    metaThemeColor.setAttribute("content", targetColor);
    document.getElementById('ntpOverlay').style.backgroundColor = targetColor;
}

function goToPage2()
{
    document.getElementById('ntpSlide1').style.display='none';
    document.getElementById('ntpSlide2').style.display='block';
    document.getElementById('centeredBlock').style.backgroundColor='#282828';
    changeThemeColor('#000');
}

var locales = {};
locales['English | Australia'] = '?hl=en-AU&gl=AU&ceid=AU:en';
locales['English | Botswana'] = '?hl=en-BW&gl=BW&ceid=BW:en';
locales['English | Canada'] = '?hl=en-CA&gl=CA&ceid=CA:en';
locales['English | Ethiopia'] = '?hl=en-ET&gl=ET&ceid=ET:en';
locales['English | Ghana'] = '?hl=en-GH&gl=GH&ceid=GH:en';
locales['English | India'] = '?hl=en-IN&gl=IN&ceid=IN:en';
locales['English | Indonesia'] = '?hl=en-ID&gl=ID&ceid=ID:en';
locales['English | Ireland'] = '?hl=en-IE&gl=IE&ceid=IE:en';
locales['English | Israel'] = '?hl=en-IL&gl=IL&ceid=IL:en';
locales['English | Kenya'] = '?hl=en-KE&gl=KE&ceid=KE:en';
locales['English | Latvia'] = '?hl=en-LV&gl=LV&ceid=LV:en';
locales['English | Malaysia'] = '?hl=en-MY&gl=MY&ceid=MY:en';
locales['English | Namibia'] = '?hl=en-NA&gl=NA&ceid=NA:en';
locales['English | New Zealand'] = '?hl=en-NZ&gl=NZ&ceid=NZ:en';
locales['English | Nigeria'] = '?hl=en-NG&gl=NG&ceid=NG:en';
locales['English | Pakistan'] = '?hl=en-PK&gl=PK&ceid=PK:en';
locales['English | Philippines'] = '?hl=en-PH&gl=PH&ceid=PH:en';
locales['English | Singapore'] = '?hl=en-SG&gl=SG&ceid=SG:en';
locales['English | South Africa'] = '?hl=en-ZA&gl=ZA&ceid=ZA:en';
locales['English | Tanzania'] = '?hl=en-TZ&gl=TZ&ceid=TZ:en';
locales['English | Uganda'] = '?hl=en-UG&gl=UG&ceid=UG:en';
locales['English | United Kingdom'] = '?hl=en-GB&gl=GB&ceid=GB:en';
locales['English | United States'] = '?hl=en-US&gl=US&ceid=US:en';
locales['English | Zimbabwe'] = '?hl=en-ZW&gl=ZW&ceid=ZW:en';
locales['Bahasa Indonesia | Indonesia'] = '?hl=id&gl=ID&ceid=ID%3Aid';
locales['Čeština | Česko'] = '?hl=cs&gl=CZ&ceid=CZ%3Acs';
locales['Deutsch | Deutschland'] = '?hl=de&gl=DE&ceid=DE%3Ade';
locales['Deutsch | Österreich'] = '?hl=de&gl=AT&ceid=AT%3Ade';
locales['Deutsch | Schweiz'] = '?hl=de&gl=CH&ceid=CH%3Ade';
locales['Español | Argentina'] = '?hl=es-419&gl=AR&ceid=AR%3Aes-419';
locales['Español | Chile'] = '?hl=es-419&gl=CL&ceid=CL%3Aes-419';
locales['Español | Colombia'] = '?hl=es-419&gl=CO&ceid=CO%3Aes-419';
locales['Español | Cuba'] = '?hl=es-419&gl=CU&ceid=CU%3Aes-419';
locales['Español | Estados Unidos'] = '?hl=es-419&gl=US&ceid=US%3Aes-419';
locales['Español | México'] = '?hl=es-419&gl=MX&ceid=MX%3Aes-419';
locales['Español | Perú'] = '?hl=es-419&gl=PE&ceid=PE%3Aes-419';
locales['Español | Venezuela'] = '?hl=es-419&gl=VE&ceid=VE%3Aes-419';
locales['Français | Belgique'] = '?hl=fr&gl=BE&ceid=BE%3Afr';
locales['Français | Canada'] = '?hl=fr-CA&gl=CA&ceid=CA:fr';
locales['Français | France'] = '?hl=fr&gl=FR&ceid=FR%3Afr';
locales['Français | Maroc'] = '?hl=fr&gl=MA&ceid=MA%3Afr';
locales['Français | Sénégal'] = '?hl=fr&gl=SN&ceid=SN%3Afr';
locales['Français | Suisse'] = '?hl=fr&gl=CH&ceid=CH%3Afr';
locales['Italiano | Italia'] = '?hl=it&gl=IT&ceid=IT%3Ait';
locales['Latviešu | Latvija'] = '?hl=lv&gl=LV&ceid=LV%3Alv';
locales['Lietuvių | Lietuva'] = '?hl=lt&gl=LT&ceid=LT%3Alt';
locales['Magyar | Magyarország'] = '?hl=hu&gl=HU&ceid=HU%3Ahu';
locales['Nederlands | België'] = '?hl=nl&gl=BE&ceid=BE%3Anl';
locales['Nederlands | Nederland'] = '?hl=nl&gl=NL&ceid=NL%3Anl';
locales['Norsk | Norge'] = '?hl=no&gl=NO&ceid=NO%3Ano';
locales['Polski | Polska'] = '?hl=pl&gl=PL&ceid=PL%3Apl';
locales['Português | Brasil'] = '?hl=pt-BR&gl=BR&ceid=BR%3Apt-419';
locales['Português | Portugal'] = '?hl=pt-PT&gl=PT&ceid=PT%3Apt-150';
locales['Română | România'] = '?hl=ro&gl=RO&ceid=RO%3Aro';
locales['Slovenčina | Slovensko'] = '?hl=sk&gl=SK&ceid=SK%3Ask';
locales['Slovenščina | Slovenija'] = '?hl=sl&gl=SI&ceid=SI%3Asl';
locales['Svenska | Sverige'] = '?hl=sv&gl=SE&ceid=SE%3Asv';
locales['Tiếng Việt | Việt Nam'] = '?hl=vi&gl=VN&ceid=VN%3Avi';
locales['Türkçe | Türkiye'] = '?hl=tr&gl=TR&ceid=TR%3Atr';
locales['Ελληνικά | Ελλάδα'] = '?hl=el&gl=GR&ceid=GR%3Ael';
locales['Български | България'] = '?hl=bg&gl=BG&ceid=BG%3Abg';
locales['Русский | Россия'] = '?hl=ru&gl=RU&ceid=RU%3Aru';
locales['Русский | Украина'] = '?hl=ru&gl=UA&ceid=UA%3Aru';
locales['Српски | Србија'] = '?hl=sr&gl=RS&ceid=RS%3Asr';
locales['Українська | Україна'] = '?hl=uk&gl=UA&ceid=UA%3Auk';
locales['עברית | ישראל'] = '?hl=he&gl=IL&ceid=IL%3Ahe';
locales['العربية | الإمارات العربية المتحدة'] = '?hl=ar&gl=AE&ceid=AE%3Aar';
locales['العربية | المملكة العربية السعودية'] = '?hl=ar&gl=SA&ceid=SA%3Aar';
locales['العربية | لبنان'] = '?hl=ar&gl=LB&ceid=LB%3Aar';
locales['العربية | مصر'] = '?hl=ar&gl=EG&ceid=EG%3Aar';
locales['मराठी | भारत'] = '?hl=mr&gl=IN&ceid=IN%3Amr';
locales['हिन्दी | भारत'] = '?hl=hi&gl=IN&ceid=IN%3Ahi';
locales['বাংলা | বাংলাদেশ'] = '?hl=bn&gl=BD&ceid=BD%3Abn';
locales['தமிழ் | இந்தியா'] = '?hl=ta&gl=IN&ceid=IN%3Ata';
locales['മലയാളം | ഇന്ത്യ'] = '?hl=ml&gl=IN&ceid=IN%3Aml';
locales['తెలుగు | భారతదేశం'] = '?hl=te&gl=IN&ceid=IN%3Ate';
locales['ไทย | ไทย'] = '?hl=th&gl=TH&ceid=TH%3Ath';
locales['中文 | 中国'] = '?hl=zh-CN&gl=CN&ceid=CN:zh-Hans';
locales['中文 | 台灣'] = '?hl=zh-TW&gl=TW&ceid=TW%3Azh-Hant';
locales['中文 | 香港'] = '?hl=zh-HK&gl=HK&ceid=HK%3Azh-Hant';
locales['日本語 | 日本'] = '?hl=ja&gl=JP&ceid=JP%3Aja';
locales['한국어 | 대한민국'] = '?hl=ko&gl=KR&ceid=KR%3Ako';

function locale_to_readabletext(string)
{
  string = string.replace('%3A', ':');
  for (var locale in locales)
  {
     if (locales[locale].replace('%3A', ':') == string)
         return locale;
  }
  return null;
}

</script>

  <!-- Container for the OneGoogleBar HTML. -->
  <div id="one-google" class="hidden" style="display: none;"></div>

  <div id="ntp-contents">
    <div id="logo" style="display: none;">
      <!-- The logo that is displayed in the absence of a doodle. -->
      <div id="logo-default" title="Google"></div>
      <!-- Logo displayed when theme prevents doodles. Doesn't fade. -->
      <div id="logo-non-white" title="Google"></div>
      <!-- A doodle, if any: its link and image. -->
      <div id="logo-doodle">
        <button id="logo-doodle-button">
          <img id="logo-doodle-image"></img>
        </button>
        <iframe id="logo-doodle-iframe" scrolling="no"></iframe>
        <!-- A spinner, visible on dark-themed NTPs, prompting the doodle -->
        <button id="logo-doodle-notifier">
          <div class="outer ball0"><div class="inner"></div></div>
          <div class="outer ball1"><div class="inner"></div></div>
          <div class="outer ball2"><div class="inner"></div></div>
          <div class="outer ball3"><div class="inner"></div></div>
        </button>
      </div>
    </div>

    <div id="fakebox-container" style="display: none;">
      <div id="fakebox">
        <div id="fakebox-text"></div>
        <input id="fakebox-input" autocomplete="off" tabindex="-1" type="url"
            aria-hidden="true">
        <div id="fakebox-cursor"></div>
        <button id="fakebox-microphone" hidden></button>
      </div>
    </div>

<style>
.full-hidden {
  opacity: 0 !important;
  position: absolute !important;
  top: -9999999px;
  left: -9999999px;
  z-index: -99999;
  width: 100vw !important;
}

.closeImgInvisible {
  display: none;
}
</style>
    <div style="position: absolute; top: 0px; right: 5px; z-index: 99999999">
    <div class="plus-item" role="button" aria-label="Add new tile" title="Add new tile" id="add-button">+</div>
    </div>
    <div id="fake-bookmarks-grid" style="display: none">
    </div>
    <div id="bookmarks-grid" class="full-hidden">
    </div>
<span id="explore-section" style="display: none">
<div style="clear: both;"></div>
<div class="configure-item-explore">
<!-- <div class="arrow-down" style="float: right;"></div>--> <span id="explore-title">Explore</span>
</div>
<div class="close-item" role="button" aria-label="Close explore" title="Close explore" id="close-explore-button">x</div>
<div style="clear: both;"></div>
    <div id="ideas-grid">
    </div>
<div style="clear: both; height: 1px;"></div>
</span>
<div id="incognito" style="display: none;width: 100%;height: 100%;background:black;">
<div style="text-align: center;padding-top:50px;">
<img style="width: 64px;border-radius: 50%"
        src="">
<br />
  <span style="color: rgb(182, 182, 182);">
<h2>Private mode</h2>
  </span>
</div>
</div>
<script>
var news_are_already_onscreen = false;
var instant_grid_done = false;
function instant_grid()
{
  instant_grid_done = true;
//  console.log('Calling instant grid generation');
  if (typeof localStorage.cachedGrid != "undefined") {
      replaceInnerHTML(document.getElementById('fake-bookmarks-grid'), localStorage.cachedGrid);
      document.getElementById('fake-bookmarks-grid').style.cssText = localStorage.cachedGridStyle;
      document.getElementById('fake-bookmarks-grid').style.display = 'block';
  }
}

if (window.chrome.embeddedSearch.newTabPage.isIncognito)
{
  document.body.style.backgroundColor='black';
  document.getElementById('incognito').style.display='block';
}
else
{
try {
  instant_grid();
  window.setTimeout(function () { if (!instant_grid_done) instant_grid(); }, 1);
}
catch (err) {
  console.log("Instant init failed, retrying later");
}
}
</script>
<style>
@-webkit-keyframes shadow-inset-center {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
  100% {
    box-shadow: 0 0 14px 0px rgba(0, 0, 0, 0.5);
  }
}
@keyframes shadow-inset-center {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
  100% {
    box-shadow: 0 0 14px 0px rgba(0, 0, 0, 0.5);
  }
}
</style>
<script>
function timeago(a) {
    var result = timeago_format(a);
    if (result[0] > 1)
      return result[0] + " " + result[1] + "s ago";
    return result[0] + " " + result[1] + " ago";
}

function timeago_format(a) {
    var b = Math.floor((new Date() - (a * 1000)) / 1000);
    var c = b / 31536000;
    if (c > 1) {
        return [Math.abs(Math.floor(c)), "year"]
    }
    c = b / 2592000;
    if (c > 1) {
        return [Math.abs(Math.floor(c)), "month"]
    }
    c = b / 86400;
    if (c > 1) {
        return [Math.abs(Math.floor(c)), "day"]
    }
    c = b / 3600;
    if (c > 1) {
        return [Math.abs(Math.floor(c)), "hour"]
    }
    c = b / 60;
    if (c > 1) {
        return [Math.abs(Math.floor(c)), "minute"]
    }
    return [Math.abs(Math.floor(b)), "second"]
}

var must_clear_news = false;
function render_news_loading()
{
  must_clear_news = true;
  document.getElementById('news').innerHTML = '<div style="clear:both;text-align:center;width: 100%"><br />&nbsp;<br /><div class="lds-dual-ring"></div></div>';
}

function add_gnews(is_primary, title, news_time, source, source_logo, link, image)
{
  var innerDiv = document.createElement('div');
  // never display images
  if (!image)
    image = '';
  var creationTime = news_time;
  var timeagoInstance = timeago();
  innerDiv.className = 'newsItem';
  innerDiv.innerHTML = '<div style="float: right; height: 128px;"><img src="' + image + '" class="newsImage" onload="this.style.opacity=\'1\';this.style.visibility=\'visible\'" onerror="this.style.visibility=\'hidden\'" /></div>'
  + '<div style="position: relative; left: 10px; font-size: medium">'
  + '<span class="newsAttribution"><img src="' + source_logo + '" onerror="this.style.display=\'none\'" style="max-height: 12px;" />&nbsp;&nbsp;<a style="color: #333" href="' + link + '">' + source + '</a></span>'
  + '<div class="newsTitle"><a style="color: #333" href="' + link + '">' 
  + title + '</a></div>'
  + '<span class="newsTime">'
  + timeago(creationTime) + '</span></a></div>';
  document.getElementById('news').appendChild(innerDiv);
  var spacer = document.createElement('div');
  spacer.style.clear = 'both';
  innerDiv.appendChild(spacer);
}

var has_valid_foryou_entries = false;
var last_offset_rendered = 0;
function render_gnews(answer, start_offset, n)
{
  last_offset_rendered = start_offset + n;
  if (must_clear_news)
  {
      must_clear_news = false;
      document.getElementById('news').innerHTML = '';
  }
          var el = document.createElement('div');
          el.style.display = 'none';
          el.baseURI = 'https://news.google.com/';
          simplifiedAnswer = '<article' + answer.split('<article').slice(1).join('<article').split('<\/script>')[0];
          simplifiedAnswer = simplifiedAnswer.replace(new RegExp('<img', 'gi'), '<source');
          simplifiedAnswer = simplifiedAnswer.replace(/ (aria-.*?|js.*?|srcset|d|data-.*?|focusable|fill|ve-.*?|alt|tabindex|role|loading)="[^"]*"/g,'')
          el.innerHTML = simplifiedAnswer;
          localStorage.cachedGNews = simplifiedAnswer;
          var articles = el.getElementsByTagName('article');
//          console.log(articles);
          var added = start_offset;
          for (var i = start_offset; i < articles.length && added < (n + start_offset); i++) {
              var article = articles[i];
              var children = article.childNodes;
              var title = null;
              var link = null;
              var image = null;
              var source = null;
              var source_logo = null;
              var is_primary = false;
              var news_time = null;
              for (var j = 0; j < children.length; j++) {
                  var child = children[j];
                  if (child.tagName == 'A')
                  {
                      link = child.href;
                  }
                  else if (child.tagName == 'FIGURE')
                  {
                      if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'SOURCE')
                      {
                          image = child.childNodes[0].src;
                          is_primary = true;
                      }
                      else if (child.childNodes.length >= 2 && child.childNodes[1].tagName == 'SOURCE') // video to play
                      {
                          image = child.childNodes[1].src;
                          is_primary = true;
                      }
                      else if (child.childNodes.length == 1 && child.childNodes[0].tagName == 'SOURCE')
                      {
                          image = child.childNodes[0].src;
                      }
                  }
                  else if (child.tagName == 'H3')
                  {
                      title = child.childNodes[0].innerText;
                  }
                  else if (child.tagName == 'DIV')
                  {
                      if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'DIV' && child.childNodes[1].tagName == 'MENU')
                      {
                          if (child.childNodes[0].childNodes[0].tagName == 'TIME')
                              news_time = child.childNodes[0].childNodes[0].dateTime;
                          else if (child.childNodes[0].childNodes[1].tagName == 'TIME')
                              news_time = child.childNodes[0].childNodes[1].dateTime;
                          if (child.childNodes[0].childNodes.length == 3 && child.childNodes[0].childNodes[2].tagName == 'TIME')
                              news_time = child.childNodes[0].childNodes[2].dateTime;
                      }
                      else if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'DIV')
                      {
                          var subNode = child.childNodes[1];
                          if (subNode.childNodes[0].tagName == 'DIV' && subNode.childNodes[1].tagName == 'MENU')
                          {
                              if (subNode.childNodes[0].tagName == 'DIV' && subNode.childNodes[1].tagName == 'MENU')
                              {
                                  if (subNode.childNodes[0].childNodes[0].tagName == 'TIME')
                                      news_time = subNode.childNodes[0].childNodes[0].dateTime;
                                  else if (subNode.childNodes[0].childNodes[1].tagName == 'TIME')
                                      news_time = subNode.childNodes[0].childNodes[1].dateTime;
                              }
                          }
                          var subNode = child.childNodes[0].childNodes[0];
                          if (subNode.childNodes.length == 3 && subNode.childNodes[0].tagName == 'DIV')
                          {
                              source = subNode.childNodes[0].innerText;
                              var sourceNode = subNode.childNodes[0].childNodes[0];
                              if ((sourceNode.tagName == 'A' || sourceNode.tagName == 'SPAN') && sourceNode.childNodes[0].tagName == 'SOURCE')
                                  source_logo = sourceNode.childNodes[0].src;
                          }
                          if (subNode.childNodes.length == 3 && subNode.childNodes[1].tagName == 'H4')
                              title = subNode.childNodes[1].innerText;
                      }
                      else if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'FIGURE')
                      {
                          if (child.childNodes[0].childNodes[0].tagName == 'SOURCE')
                              image = child.childNodes[0].childNodes[0].src;
                          else if (child.childNodes[0].childNodes[1].tagName == 'SOURCE') // video to play
                              image = child.childNodes[0].childNodes[1].src;
                          var divSubNode = child.childNodes[1];
                          if (divSubNode.childNodes.length == 3 && divSubNode.childNodes[0].tagName == 'DIV')
                          {
                              source = divSubNode.childNodes[0].innerText;
                              var sourceNode = divSubNode.childNodes[0].childNodes[0];
                              if ((sourceNode.tagName == 'A' || sourceNode.tagName == 'SPAN') && sourceNode.childNodes[0].tagName == 'SOURCE')
                                  source_logo = sourceNode.childNodes[0].src;
                          }
                          if (divSubNode.childNodes.length == 3 && divSubNode.childNodes[1].tagName == 'H4')
                              title = divSubNode.childNodes[1].innerText;
                      } else if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'SOURCE') {
                        if (child.childNodes[0].tagName == 'SOURCE' && child.childNodes[1].tagName == 'A') {
                          source_logo = child.childNodes[0].src;
                          if (child.childNodes[1].innerText)
                            source = child.childNodes[1].innerText;
                        }
                        if (child.childNodes.length == 3) {
                          if (child.childNodes[0].tagName == 'SOURCE' && child.childNodes[1].tagName == 'SOURCE' && child.childNodes[2].tagName == 'A') {
                            source_logo = child.childNodes[0].src;
                            if (child.childNodes[2].innerText)
                              source = child.childNodes[2].innerText;
                          }
                        }
                        if (child.childNodes.length == 4) {
                          if (child.childNodes[0].tagName == 'SOURCE' && child.childNodes[1].tagName == 'SOURCE'
                           && child.childNodes[2].tagName == 'SOURCE' && child.childNodes[3].tagName == 'A') {
                            source_logo = child.childNodes[0].src;
                            if (child.childNodes[3].innerText)
                              source = child.childNodes[3].innerText;
                          }
                        }
                      } else if (child.childNodes.length == 1 && child.childNodes[0].tagName == 'A')
                      {
                          subNode = child.childNodes[0];
                          source = subNode.innerText;
                          var sourceNode = subNode.childNodes[0];
                          if (sourceNode.tagName == 'SOURCE')
                             source_logo = sourceNode.src;
                      }
                      else if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'A')
                      {
                          source = child.childNodes[1].innerText;
                          var sourceNode = child.childNodes[0].childNodes[0];
                          if (sourceNode.tagName == 'SOURCE')
                             source_logo = sourceNode.src;
                      }
                      else if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'SPAN')
                      {
                          source = child.childNodes[1].innerText;
                          var sourceNode = child.childNodes[0].childNodes[0];
                          if (sourceNode.tagName == 'SOURCE')
                             source_logo = sourceNode.src;
                       } else if (child.childNodes.length >= 2 && child.childNodes[0].tagName == 'SOURCE') {
                         if (child.childNodes[1].innerText)
                           source = child.childNodes[1].innerText;
                       }
                  }
              }
              try {
                if (link == null)
                    link = article.querySelector("a.VDXfz").href;
              } catch {}
              try {
                if (title == null)
                    title = article.querySelector("h4 a.DY5T1d").textContent;
              } catch {}
              try {
                if (image == null)
                    image = article.querySelector(".QwxBBf").src;
              } catch {}
              try {
                if (source == null)
                    source = article.querySelector("a.wEwyrc").textContent;
              } catch {}
              try {
                if (source_logo == null)
                    source_logo = article.querySelector(".wsLqz source").src;
              } catch {}
              try {
                if (news_time == null || news_time == 0)
                    news_time = article.querySelector(".WW6dff").getAttribute("datetime");
              } catch {}
              if (news_time && parseInt(news_time.substr(news_time.lastIndexOf(":") + 2)) > 1518000000)
                  news_time = parseInt(news_time.substr(news_time.lastIndexOf(":") + 2));
              else
                  news_time = parseInt(Date.parse(news_time) / 1000);
              if (link)
                  link = link.replace('chrome-search://local-ntp/', 'https://news.google.com/');
            
              if (link && image && title) {
//                  console.log('Title: ' + title);
                  add_gnews(is_primary, title, news_time, source, source_logo, link, image);
                  added++;
                  news_are_already_onscreen = true;
                  localStorage.needFetch = false;
              }
          }
          if (articles.length > (i + 1) && i <= 29)
          {
            document.getElementById('newsMore').innerHTML='<div style="color: #8AB4F8; font-size: 24px; width: 100%; text-align: center"><b>...</b></div><br />&nbsp;<br />';
          } else {
            document.getElementById('newsMore').innerHTML='';
          }
}

var closeImg = '';
document.getElementById('add-button').addEventListener('click', create_new_item);

var longpress = false;
var presstimer = null;
var longtarget = null;
var iseditable = false;

function load_more_news()
{
  localStorage.lastOffsetRendered = last_offset_rendered;
  render_gnews(localStorage.cachedGNews, last_offset_rendered, 10);
}

function process_cancel(e) {
    console.log('We received process_cancel');
    console.log(e);
    if (iseditable)
    {
      e.preventDefault();
      return ;
    }
    if (presstimer !== null) {
        clearTimeout(presstimer);
        presstimer = null;
    }

    this.classList.remove("longpress");
};

function process_body_click(e) {
  if (iseditable) {
      toggle_edit_mode();
      e.preventDefault();
  }
}

function process_click(e) {
    console.log('We received process_click');
    console.log(e);
    if (iseditable)
      return ;
    e.preventDefault();
    if (presstimer !== null) {
        clearTimeout(presstimer);
        presstimer = null;
    }

    this.classList.remove("longpress");

    if (longpress) {
        return false;
    }
};

function process_start(e) {
    if (iseditable)
      return ;
//    e.preventDefault();

    if (e.type === "click" && e.button !== 0) {
        return;
    }

    longpress = false;

    this.classList.add("longpress");

    presstimer = setTimeout(function() {
        toggle_edit_mode();
        longpress = true;
    }, 550);

    return false;
};

function arrayBufferToBase64(buffer) {
  var binary = '';
  var bytes = [].slice.call(new Uint8Array(buffer));

  bytes.forEach((b) => binary += String.fromCharCode(b));

  return window.btoa(binary);
};

function invalidate_image(item)
{
  console.log("Invalidating item: " + item.title);
  var parser = document.createElement('a');
  parser.href = item.title;
  var rootDomain = psl.get(parser.hostname);
  console.log("Invalidating rootDomain: " + rootDomain);
  item.src = "data:image/svg+xml;base64," + btoa(jdenticon.toSvg(parser.hostname, 64));
  localStorage.setItem('icon-' + rootDomain, item.src);
  localStorage.setItem('lastShown-' + rootDomain, Math.floor(Date.now() / 1000));
}

function remove_favorite(e)
{
  console.log("Removing favorite");
  console.log(e);
  item = e.target;
  item = item.parentNode;
  console.log("Removing item");
  globalGrid.disconnect(item);
}

var nItemsAdded = 0;

function add_favorite_idea(name, click_url, impression_url, image_url)
{
  var rootDomain = 'idea-' + name;
  var innerDiv = document.createElement('div');
  innerDiv.className = 'grid-item grid-idea';
  var cachedImage = localStorage.getItem('icon-' + rootDomain);
  localStorage.setItem('lastShown-' + rootDomain, Math.floor(Date.now() / 1000));
  var imageUri = null;
  var randomId = Math.random().toString(36).substr(2, 9) + Math.random().toString(36).substr(2, 9) + Math.random().toString(36).substr(2, 9);
  if (cachedImage != null) {
    imageUri = cachedImage;
    console.log('Loading icon for ' + rootDomain + ' from cache');
  } else {
      console.log('Fetching icon for ' + rootDomain);
      loadingImage = "data:image/svg+xml;base64," + btoa('<svg width="85px"  height="85px"  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="lds-tail">    <defs>      <filter id="tail-0.a4db4fdd84ecd" x="-100%" y="-100%" width="300%" height="300%" color-interpolation-filters="sRGB">        <feGaussianBlur in="SourceGraphic" stdDeviation="3"></feGaussianBlur>        <feColorMatrix mode="matrix" values="1 0 0 0 0   0 1 0 0 0   0 0 1 0 0   0 0 0 60 -40" result="cm"></feColorMatrix>      </filter>    </defs>    <g ng-attr-filter="url(#{{config.filterid}})" filter="url(#tail-0.a4db4fdd84ecd)" transform="rotate(54 50 50)">      <animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;360 50 50" keyTimes="0;1" dur="4s" begin="0s" repeatCount="indefinite"></animateTransform>      <g transform="rotate(333.474 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="19" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.13333333333333333 0 0.03333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(331.178 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="18" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.16666666666666669 0 0.06666666666666667 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(328.576 50.0001 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="17" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.2 0 0.1 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(325.612 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="16" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.23333333333333334 0 0.13333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(322.212 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="15" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.26666666666666666 0 0.16666666666666666 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(318.287 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="14" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.30000000000000004 0 0.2 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(314.708 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="13" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.33333333333333337 0 0.23333333333333334 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(309.018 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="12" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.3666666666666667 0 0.26666666666666666 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(302.443 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="11" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.4 0 0.3 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(294.767 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="10" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.43333333333333335 0 0.3333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(285.715 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="9" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.4666666666666667 0 0.36666666666666664 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(274.96 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="8" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.5 0 0.4 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(263.29 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="7" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.5333333333333333 0 0.43333333333333335 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(247.243 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="6" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.5666666666666667 0 0.4666666666666667 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(233.28 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="5" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.6 0 0.5 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(210.448 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="4" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.6333333333333333 0 0.5333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(189.723 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="3" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.6666666666666666 0 0.5666666666666667 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(167.547 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="2" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.7 0 0.6 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(151.39 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="1" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.7333333333333333 0 0.6333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(134.242 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="0" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.7666666666666666 0 0.6666666666666666 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>    </g>  </svg>');
      imageUri = loadingImage;
try {
      fetch(image_url).then(function(response) {
        return response.arrayBuffer();
      })
      .then(function(answer) {
        localStorage.setItem('icon-' + rootDomain, 'data:image/png;base64,' + arrayBufferToBase64(answer));
        localStorage.setItem('lastShown-' + rootDomain, Math.floor(Date.now() / 1000));
        document.getElementById('icon' + randomId).src = 'data:image/png;base64,' + arrayBufferToBase64(answer);
        console.log('Icon for ' + rootDomain + ' is now fetched');
      });
} catch (err) {
      console.log('Fetch failed for: ' + err.message);
}
  }
  if (impression_url && impression_url != 'about:blank')
    navigator.sendBeacon(impression_url);
  innerDiv.innerHTML = '<a id="tile_target" href="' + click_url + '"><img border="0" class="grid-image" title="' + name + '" src="' + imageUri + '" id="icon' + randomId + '" onError="invalidate_image(this)" width="64" style="max-height: 64px; border-radius: 4px;" /><span style="width: 60px; line-height: 15px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; display: inline-block">' + name + '</span></a>';
  innerDiv.style.minHeight = '64px';

//  innerDiv.querySelector('#closeImg').addEventListener("touchstart", remove_favorite);
//  innerDiv.querySelector('#tile_target').addEventListener("touchstart", process_start);
  document.body.addEventListener("click", process_body_click);
//  innerDiv.querySelector('#tile_target').addEventListener("touchend", process_cancel);
  document.getElementById('ideas-grid').appendChild(innerDiv);
}

function add_favorite(item)
{
  var parser = document.createElement('a');
  parser.href = item.url;
  // Our intent is buzz.blogspot.com to stay buzz.blogspot.com
  // and m.wikipedia.org to become wikipedia.org
  var rootDomain = psl.get(parser.hostname);
  var innerDiv = document.createElement('div');
  innerDiv.className = 'grid-item';
  var cachedImage = localStorage.getItem('icon-' + rootDomain);
  localStorage.setItem('lastShown-' + rootDomain, Math.floor(Date.now() / 1000));
  var imageUri = null;
  var randomId = Math.random().toString(36).substr(2, 9) + Math.random().toString(36).substr(2, 9) + Math.random().toString(36).substr(2, 9);
  if (nItemsAdded++ < 10) {
    console.log('Favorite - Preconnecting to: ' + item.url);
    preconnectTo(item.url);
    if (item.url.startsWith('http://'))
      preconnectTo(item.url.replace('http://', 'https://'));
  }
  if (cachedImage != null) {
    imageUri = cachedImage;
    console.log('Loading icon for ' + rootDomain + ' from cache');
  } else {
      console.log('Fetching icon for ' + rootDomain);
      loadingImage = "data:image/svg+xml;base64," + btoa('<svg width="85px"  height="85px"  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="lds-tail">    <defs>      <filter id="tail-0.a4db4fdd84ecd" x="-100%" y="-100%" width="300%" height="300%" color-interpolation-filters="sRGB">        <feGaussianBlur in="SourceGraphic" stdDeviation="3"></feGaussianBlur>        <feColorMatrix mode="matrix" values="1 0 0 0 0   0 1 0 0 0   0 0 1 0 0   0 0 0 60 -40" result="cm"></feColorMatrix>      </filter>    </defs>    <g ng-attr-filter="url(#{{config.filterid}})" filter="url(#tail-0.a4db4fdd84ecd)" transform="rotate(54 50 50)">      <animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;360 50 50" keyTimes="0;1" dur="4s" begin="0s" repeatCount="indefinite"></animateTransform>      <g transform="rotate(333.474 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="19" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.13333333333333333 0 0.03333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(331.178 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="18" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.16666666666666669 0 0.06666666666666667 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(328.576 50.0001 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="17" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.2 0 0.1 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(325.612 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="16" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.23333333333333334 0 0.13333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(322.212 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="15" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.26666666666666666 0 0.16666666666666666 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(318.287 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="14" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.30000000000000004 0 0.2 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(314.708 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="13" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.33333333333333337 0 0.23333333333333334 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(309.018 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="12" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.3666666666666667 0 0.26666666666666666 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(302.443 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="11" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.4 0 0.3 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(294.767 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="10" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.43333333333333335 0 0.3333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(285.715 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="9" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.4666666666666667 0 0.36666666666666664 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(274.96 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="8" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.5 0 0.4 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(263.29 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="7" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.5333333333333333 0 0.43333333333333335 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(247.243 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="6" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.5666666666666667 0 0.4666666666666667 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(233.28 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="5" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.6 0 0.5 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(210.448 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="4" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.6333333333333333 0 0.5333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(189.723 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="3" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.6666666666666666 0 0.5666666666666667 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(167.547 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="2" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.7 0 0.6 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(151.39 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="1" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.7333333333333333 0 0.6333333333333333 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>      <g transform="rotate(134.242 50 50)">        <g ng-attr-transform="translate(50 {{config.cy}})" transform="translate(50 19.6)">          <circle cx="0" cy="0" r="0" ng-attr-fill="{{config.fill}}" ng-attr-transform="scale({{config.scale}})" fill="#ff7c81" transform="scale(0.48)"></circle>        </g>        <animateTransform attributeName="transform" calcMode="spline" type="rotate" values="0 50 50;360 50 50" keyTimes="0;1" ng-attr-dur="{{config.speed2}}" keySplines="0.7666666666666666 0 0.6666666666666666 1" repeatCount="indefinite" dur="1"></animateTransform>      </g>    </g>  </svg>');
      imageUri = loadingImage;
try {
      fetch('https://logos.kiwibrowser.com/' + rootDomain).then(function(response) {
        return response.arrayBuffer();
      })
      .then(function(answer) {
        localStorage.setItem('icon-' + rootDomain, 'data:image/png;base64,' + arrayBufferToBase64(answer));
        document.getElementById('icon' + randomId).src = 'data:image/png;base64,' + arrayBufferToBase64(answer);
        console.log('Icon for ' + rootDomain + ' is now fetched');
      });
} catch (err) {
      console.log('Fetch failed for: ' + err.message);
}
  }
  innerDiv.innerHTML = '<img id="closeImg" src="' + closeImg + '" class="closeImg closeImgInvisible" height="20" width="20" style="position: absolute; right: 0px; border: 0px;" /><a id="tile_target" href="' + item.url + '"><img border="0" class="grid-image serverIdea" title="' + item.url + '" src="' + imageUri + '" id="icon' + randomId + '" onError="invalidate_image(this)" width="64" style="max-height: 64px; border-radius: 4px;" /><span style="width: 60px; line-height: 15px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; display: inline-block">' + rootDomain + '</span></a>';
  innerDiv.style.minHeight = '64px';

  innerDiv.querySelector('#closeImg').addEventListener("touchstart", remove_favorite);
  innerDiv.querySelector('#tile_target').addEventListener("touchstart", process_start);
  document.body.addEventListener("click", process_body_click);
  innerDiv.querySelector('#tile_target').addEventListener("touchend", process_cancel);
  document.getElementById('bookmarks-grid').appendChild(innerDiv);
}

var globalGrid = false;
var bookmarksGrid = document.getElementById("bookmarks-grid");
var ideasGrid = document.getElementById("ideas-grid");

function save_grid_snapshot()
{
  if (!document.getElementById('bookmarks-grid').style.cssText)
    return ;
  // Maximum 1 update per 0.1s (100ms)
  if ((typeof localStorage.cachedGridUpdate == "undefined") || ((Date.now() / 1000) - localStorage.cachedGridUpdate) >= 0.1) {
    var parser = document.createElement('span');
    parser.innerHTML = document.getElementById('bookmarks-grid').innerHTML;
    var elementsToIgnore = parser.getElementsByClassName('grid-idea');
    for (var i = 0; i < elementsToIgnore.length; i++)
      elementsToIgnore[i].remove();
    localStorage.cachedGrid = parser.innerHTML;
    localStorage.cachedGridStyle = document.getElementById('bookmarks-grid').style.cssText;
//    console.log("Saving grid snapshot and style is " + localStorage.cachedGridStyle);
    localStorage.cachedGridUpdate = (Date.now() / 1000);
  }
}

function add_to_storage(el)
{
  var storedItems = JSON.parse(localStorage.storedItems);
  offset = storedItems.length;
  var url = el.querySelector('#tile_target').href;
  storedItems[offset] = {url: url}
  localStorage.storedItems = JSON.stringify(storedItems);
  console.log("Add to storage, adding to offset " + offset + " the URL: " + url);
}

function swap_if_ready()
{
  if (bookmarksGrid.style.cssText.includes("height"))
  {
    document.getElementById('fake-bookmarks-grid').style.display='none';
    bookmarksGrid.classList.remove("full-hidden");
  }
}

function fetch_tiles_from_most_visited()
{
  if (window.chrome.embeddedSearch.newTabPage.isIncognito) {
    localStorage.triedToLoadMostVisited = 99999;
    return;
  }
  if (typeof localStorage.triedToLoadMostVisited == "undefined")
    localStorage.triedToLoadMostVisited = 0;
  localStorage.triedToLoadMostVisited = parseInt(localStorage.triedToLoadMostVisited) + 1;
  if ((typeof localStorage.cachedTilesUpdate == "undefined") || ((Date.now() / 1000) - localStorage.cachedTilesUpdate) > 43200) {
  console.log("Fetching tiles from most visited because:");
  if (typeof localStorage.cachedTilesUpdate == "undefined")
    console.log(" it is the first time");
  else
    console.log(" last update is out of date");
  if (typeof localStorage.useCustomTiles == "undefined" || localStorage.useCustomTiles == "false") {
    if (chrome.embeddedSearch.newTabPage.mostVisitedAvailable) {
      localStorage.storedItems = JSON.stringify([]);
      var pages = chrome.embeddedSearch.newTabPage.mostVisited;
      var storedItems = JSON.parse(localStorage.storedItems);
      for (var i = 0; i < Math.min(8, pages.length); ++i) {
         offset = storedItems.length;
         storedItems[offset] = {url: chrome.embeddedSearch.newTabPage.getMostVisitedItemData(pages[i].rid).url}
         add_favorite(storedItems[offset]);
      }
      localStorage.storedItems = JSON.stringify(storedItems);
      localStorage.cachedTilesUpdate = (Date.now() / 1000);
    }
  }
  } else {
    console.log("Not fetching tiles from most visited, as we have to do once every day");
    if (typeof localStorage.storedItems != "undefined") { var storedItems = JSON.parse(localStorage.storedItems); for (var i = 0; i < storedItems.length; i++) { add_favorite(storedItems[i]); } }
  }
}

function toggle_edit_mode()
{
  if (globalGrid.isDragifierOn()) {
    iseditable = false;
    globalGrid.dragifierOff();
    Array.prototype.forEach.call(document.getElementsByClassName("grid-item"), function (el) { if (!el.classList.contains('grid-idea')) { el.style.WebkitAnimation = 'none'; } });
    Array.prototype.forEach.call(document.getElementsByClassName('closeImg'), function (el) { el.classList.add('closeImgInvisible'); });
  } else {
    iseditable = true;
    globalGrid.dragifierOn();
    Array.prototype.forEach.call(document.getElementsByClassName("grid-item"), function (el) { if (!el.classList.contains('grid-idea')) { el.style.WebkitAnimation = 'shadow-inset-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both'; } });
    Array.prototype.forEach.call(document.getElementsByClassName('closeImg'), function (el) { el.classList.remove('closeImgInvisible'); });
  }
  window.setTimeout(function () { save_grid_snapshot(); }, 100);
}

function select_locale(locale)
{
  localStorage.newsLocale = locales[locale];
  localStorage.removeItem('cachedNewsUpdate');
  localStorage.removeItem('cachedGNews');
  document.location = 'chrome-search://local-ntp/local-ntp.html';
}

function configure_news()
{
  document.getElementById("localeDropdown").classList.toggle('show');
  var buf = '<ul class="localesList">';
  for (var locale in locales)
  {
      if (locale_to_readabletext(localStorage.newsLocale) == locale)
        buf += '<li class="localesListSelected"><b>' + locale + '</b></li>';
      else
        buf += '<li class="localesListUnselected"><a href="#" onClick="javascript:select_locale(\'' + locale + '\'); return false">' + locale + '</a></li>';
  }
  buf += '</ul>';
  document.getElementById("localeDropdown").innerHTML = buf;
}

window.onclick = function(event) {
  if (!event.target.matches('.dropbtn') && !event.target.matches('#locale') && !event.target.matches('.arrow-down')) {
    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');
      }
    }
  }
}

function close_explore()
{
  localStorage.hideExplore = true;
  document.getElementById('explore-section').style.display='none';
  document.getElementById('close-explore-button').style.display='none';
  document.getElementById('enable-explore-button').style.display='inline-block';
  document.getElementById('enable-explore-button').addEventListener('click', enable_explore);
}

function close_news()
{
  localStorage.hideNews = true;
  document.getElementById('news').style.display='none';
  document.getElementById('newsMore').style.display='none';
  document.getElementById('configure-button').style.display='none';
  document.getElementById('close-button').style.display='none';
  document.getElementById('enable-news-button').style.display='inline-block';
  document.getElementById('enable-news-button').addEventListener('click', enable_news);
}

function close_information()
{
  localStorage.hideInformation = true;
  document.getElementById('informationPromo').style.display='none';
}

function create_new_item()
{
  preconnectTo('https://logos.kiwibrowser.com');
  var url = prompt("Enter website address", "http://");
  url = url.trim();
  url = url.replace(' ', '.');
  var parser = document.createElement('a');
  parser.href = url;
  // Our intent is buzz.blogspot.com to stay buzz.blogspot.com
  // and m.wikipedia.org to become wikipedia.org
  var rootDomain = psl.get(parser.hostname);
  if (!rootDomain)
    return ;
  if (typeof localStorage.storedItems == "undefined" || localStorage.storedItems == "")
      localStorage.storedItems = JSON.stringify([]);
  var storedItems = JSON.parse(localStorage.storedItems);
  offset = storedItems.length;
  storedItems[offset] = {url: url}
  add_favorite(storedItems[offset]);
  localStorage.storedItems = JSON.stringify(storedItems);
  globalGrid.toggle("scaleWithFade");
  globalGrid.appendNew();
  window.setTimeout(function () { save_grid_snapshot(); }, 200);
  window.setTimeout(function () { save_grid_snapshot(); }, 800);
  localStorage.useCustomTiles = "true";
}
</script>

<div style="clear: both;"></div>
<div id="informationPromo" style="display: none;">
<div style="position: relative; color: #888;z-index: 2147483647;margin: 10px;border-radius: 5px;padding: 5px;border: 1px dotted #efefef;background: #fefefe;">
<table>
<tbody><tr>
<td style="width: 99%">
<div><b>Sabia que...?</b></div>
<div>
As extensões para Kiwi são gratuitas e qualquer pessoa pode criar uma.
<br />
Se alguém se oferecer para comprar um robô ou uma extensão para Kiwi, tenha cuidado.
</div>
    </td>
    <td style="width: 30px"><div style="background-color: #42B1FF; padding: 10px;" id="informationClose"><a style="color: #fff" target="#" onClick="javascript:close_information();return false;"><b>OK</b></a></div></td>
    </tr></tbody></table>
</div>
</div>
<div class="configure-item dropbtn" role="button" aria-label="Choose news region" title="Choose news region" id="configure-button"><div class="arrow-down" style="float: right;"></div> <span id="locale"></span></div>
<div class="close-item" role="button" aria-label="Close news" title="Close news" id="close-button">x</div>
<br />
  <div id="localeDropdown" class="dropdown-content">
  </div>
<div id="newsHeader" style="display: none;"></div>
<div id="news"></div>
<div id="newsMore"></div>
<script>
if (window.chrome.embeddedSearch.newTabPage.isIncognito || typeof localStorage.hideExplore != "undefined") {
  document.getElementById('explore-section').style.display='none';
} else {
  if (document.getElementById('close-explore-button'))
    document.getElementById('close-explore-button').addEventListener('click', close_explore);
}
if (window.chrome.embeddedSearch.newTabPage.isIncognito || typeof localStorage.hideNews != "undefined") {
  document.getElementById('news').style.display='none';
  document.getElementById('newsMore').style.display='none';
  document.getElementById('configure-button').style.display='none';
  document.getElementById('close-button').style.display='none';
} else {
  if (typeof localStorage.newsLocale == "undefined") {
      localStorage.newsLocale = '';
  } else if (localStorage.newsLocale != '') {
      document.getElementById('locale').innerHTML = locale_to_readabletext(localStorage.newsLocale);
  }
  if (document.getElementById('configure-button'))
    document.getElementById('configure-button').addEventListener('click', configure_news);
  if (document.getElementById('close-button'))
    document.getElementById('close-button').addEventListener('click', close_news);
  if (document.getElementById('newsMore'))
    document.getElementById('newsMore').addEventListener('click', load_more_news);
  preconnectTo('https://news.google.com');
}

async function render_news_async() {
if (!window.chrome.embeddedSearch.newTabPage.isIncognito)
{
//  console.log('News locale is ' + localStorage.newsLocale);
  if (typeof localStorage.cachedGNews != "undefined" && typeof localStorage.hideNews == "undefined")
  {
//    console.log('Rendering GNews from cache');
    render_gnews(localStorage.cachedGNews, 0, 10);
    if (typeof localStorage.lastOffsetRendered != "undefined")
    {
        for (var i = 10; i <= localStorage.lastOffsetRendered; i += 10)
            render_gnews(localStorage.cachedGNews, i, 10);
    }
  }
}
}
window.setTimeout(function () { render_news_async(); }, 1);

if (!window.chrome.embeddedSearch.newTabPage.isIncognito)
{
  if ((typeof localStorage.cachedNewsUpdate == "undefined") || ((Date.now() / 1000) - localStorage.cachedNewsUpdate) > 3000 || (typeof localStorage.needFetch == "undefined")) {
    if (typeof localStorage.hideNews == "undefined") {

has_valid_foryou_entries = false;
if (news_are_already_onscreen) {
      localStorage.needFetch = false;
} else {
      document.getElementById('newsMore').innerHTML='';
      last_offset_rendered = 0;
      localStorage.lastOffsetRendered = 0;
      render_news_loading();
}

async function get_news() {
try {
      await fetch('https://news.google.com/foryou' + localStorage.newsLocale, { method: 'GET', credentials: 'include' })
        .then(function(response) {
//          console.log('Gnews: received answer from personalized feed');
          if (response.url.includes("&ceid=")) {
//            console.log('Gnews: Detected ceid (personalized)');
            localStorage.newsLocale = response.url.substr(response.url.lastIndexOf('?'));
            document.getElementById('locale').innerHTML = locale_to_readabletext(localStorage.newsLocale);
          }
          console.log("We set has_valid_foryou_entries to true");
          has_valid_foryou_entries = true;
          return response.text();
        })
        .then(function(answer) {
          if (answer != localStorage.cachedGNews && !news_are_already_onscreen)
          {
            render_gnews(answer, 0, 10);
          }
          localStorage.cachedGNews = answer;
          localStorage.cachedNewsUpdate = (Date.now() / 1000);
        });
} catch (err) {
      console.log('Fetch news failed for: ' + err.message);
}

console.log("Processing standard news feed");
console.log(has_valid_foryou_entries);
try {
if (!has_valid_foryou_entries)
{
if (!news_are_already_onscreen) {
      last_offset_rendered = 0;
      localStorage.lastOffsetRendered = 0;
      render_news_loading();
}
      await fetch('https://news.google.com/topics/CAAqJggKIiBDQkFTRWdvSUwyMHZNRFZxYUdjU0FtVnVHZ0pWVXlnQVAB' + localStorage.newsLocale, { method: 'GET', credentials: 'omit' })
        .then(function(response) {
          if (response.url.includes("&ceid=")) {
//            console.log('Gnews: Detected ceid (standard)');
            localStorage.newsLocale = response.url.substr(response.url.lastIndexOf('?'));
            document.getElementById('locale').innerHTML = locale_to_readabletext(localStorage.newsLocale);
          }
          return response.text();
        })
        .then(function(answer) {
//          console.log('Gnews: received answer from standard feed');
          if (answer != localStorage.cachedGNews && !news_are_already_onscreen)
          {
            render_gnews(answer, 0, 10);
          }
          localStorage.cachedGNews = answer;
          localStorage.cachedNewsUpdate = (Date.now() / 1000);
        });
}
} catch (err) {
      console.log('Fetch generic news failed for: ' + err.message);
}


} // async
get_news();

    }
  }
}

</script>
    <div id="attribution"><div id="attribution-text"></div></div>

    <div id="edit-bg" tabindex="0" hidden>
      <button id="edit-bg-gear"></button>
    </div>

    <div id="edit-bg-overlay">
      <div id="edit-bg-dialog">
        <div id="edit-bg-title"></div>
        <div id="edit-bg-google-photos" class="bg-option" tabindex="0" hidden>
          <div class="bg-option-img"></div>
          <div id="edit-bg-google-photos-text" class="bg-option-text"></div>
        </div>
        <div id="edit-bg-default-wallpapers" class="bg-option" tabindex="0">
          <div class="bg-option-img"></div>
          <div id="edit-bg-default-wallpapers-text" class="bg-option-text">
          </div>
        </div>
        <div id="edit-bg-upload-image" class="bg-option" tabindex="0" hidden>
          <div class="bg-option-img"></div>
          <div id="edit-bg-upload-image-text" class="bg-option-text"></div>
        </div>
        <div id="edit-bg-restore-default" class="bg-option" tabindex="0">
          <div class="bg-option-img"></div>
          <div id="edit-bg-restore-default-text" class="bg-option-text"></div>
        </div>
      </div>
    </div>

  </div>

  <dialog id="bg-sel-menu-overlay">
    <div id="bg-sel-menu">
      <div id="bg-sel-title-bar">
      <div id="bg-sel-back"></div>
      <div id="bg-sel-title"></div>
      </div>
      <div id="bg-sel-tiles"></div>
      <div id="bg-sel-footer">
        <label id="bg-daily-refresh" class="switch">
          <input type="checkbox">
          <span class="toggle"></span>
        </label>
        <div id="bg-sel-refresh-text"></div>
        <div id="bg-sel-footer-done"></div>
      </div>
    </div>
  </dialog>

  <dialog id="voice-overlay-dialog" class="overlay-dialog">
    <div id="voice-overlay" class="overlay-hidden">
      <button id="voice-close-button" class="close-button">&times;</button>
      <div id="voice-outer" class="outer">
        <div class="inner-container">
          <div id="voice-button-container" class="button-container">
            <!-- The audio level animation. -->
            <span id="voice-level" class="level"></span>
            <!-- The microphone button. -->
            <span id="voice-button" class="button">
              <!-- The microphone icon (in CSS). -->
              <div class="microphone">
                <span class="receiver"></span>
                <div class="wrapper">
                  <span class="stem"></span>
                  <span class="shell"></span>
                </div>
              </div>
            </span>
          </div>
          <div class="text-container">
            <!-- Low confidence text underneath high confidence text. -->
            <span id="voice-text-i" class="voice-text"></span>
            <!-- High confidence text on top of low confidence text. -->
            <span id="voice-text-f" class="voice-text"></span>
          </div>
        </div>
      </div>
    </div>
  </dialog>

  <div id="one-google-end-of-body"></div>
<div style="clear: both;"></div>
<br />
<div id="bottom_panel" style="text-align: center; width: 100%; visibility: hidden">
<input type="file" name="import-file" id="import-file" style="opacity: 0;position: absolute;z-index: -1;">
<span style="text-align: center; color: #cccccc; padding-right: 10px" id="enable-news-button">Show news</span>
<span style="text-align: center; color: #cccccc; padding-right: 10px" id="enable-explore-button">Show explore</span>
<label for="import-file"><span style="text-align: center; color: #cccccc; padding-right: 10px" id="import-button">Import</span></label>
<span style="text-align: center; color: #cccccc; padding-right: 10px" id="export-button">Export</span>
<span style="text-align: center; color: #cccccc; padding-right: 10px" id="reset-button">Reset</span>
</div>
<br />
<script>
function enable_news()
{
  localStorage.removeItem('hideNews');
  location.reload();
}
function enable_explore()
{
  localStorage.removeItem('hideExplore');
  location.reload();
}
function reset_page()
{
  if (confirm("This will reset all the homepage back to default, are you sure ?"))
  {
    var hideInformation = false;
    if (typeof localStorage.hideInformation != "undefined" && localStorage.hideInformation != false) {
      hideInformation = true;
    }
    localStorage.clear();
    localStorage.hideInformation = hideInformation;
    location.reload();
  }
}
if (typeof localStorage.hideInformation == "undefined" || (typeof localStorage.hideInformation != "undefined" && localStorage.hideInformation == false)) {
  if (navigator.language.includes('pt'))
    document.getElementById('informationPromo').style.display='block';
}
if (window.chrome.embeddedSearch.newTabPage.isIncognito)
{
  document.getElementById('bottom_panel').style.display='none';
}
else
{
  document.getElementById('bottom_panel').style.visibility='visible';
  document.getElementById('enable-news-button').addEventListener('click', enable_news);
  document.getElementById('enable-explore-button').addEventListener('click', enable_explore);
  document.getElementById('reset-button').addEventListener('click', reset_page);
  document.getElementById('export-button').onclick = function(){
    var localStorageCopy = JSON.parse(JSON.stringify(localStorage));
    var values = Object.values(localStorageCopy),
       keys = Object.keys(localStorageCopy),
       i = keys.length;
    while ( i-- ) {
      if (keys[i].startsWith('cached') || keys[i].startsWith('icon-'))
        delete localStorageCopy[keys[i]];
    }
    var dataStr = JSON.stringify(localStorageCopy);
    var dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
    var dateObj = new Date();
    var month = dateObj.getUTCMonth() + 1; //months from 1-12
    var day = dateObj.getUTCDate();
    var year = dateObj.getUTCFullYear();
    var exportFileDefaultName = 'kiwi_homepage_'+year+'-'+month+'-'+day+'.json';
    var linkElement = document.createElement('a');
    linkElement.setAttribute('href', dataUri);
    linkElement.setAttribute('download', exportFileDefaultName);
    linkElement.click();
  }
  document.getElementById('import-file').onchange = function(){
    var file = this.files[0];
    var reader = new FileReader();
    reader.onload = function(progressEvent){
      var content = this.result;
      var parsedContent = JSON.parse(content);

      var values = Object.values(parsedContent),
        keys = Object.keys(parsedContent),
        i = keys.length;
      while ( i-- ) {
        localStorage.setItem(keys[i], values[i]);
      }
      document.location.reload();
    };
    reader.readAsText(file);
  };
}
if (typeof localStorage.hideNews == "undefined") {
  document.getElementById('enable-news-button').style.display='none';
}
if (typeof localStorage.hideExplore == "undefined") {
  document.getElementById('enable-explore-button').style.display='none';
}
</script>
<br />&nbsp;<br />
<script src="./local-ntp.js"></script>
<script>
function cleanUpOldTilesIdeas() {
  var values = Object.values(localStorage),
       keys = Object.keys(localStorage),
       i = keys.length;
    while ( i-- ) {
      if (keys[i].startsWith('lastShown-idea-')) {
        var tile_name = keys[i].substring('lastShown-idea-'.length);
        var difference = Math.floor(Date.now() / 1000) - parseInt(localStorage[keys[i]]);
        if (difference > (86400 * 7)) {
          console.log('Dropping tile idea: ' + keys[i]);
          delete localStorage[keys[i]];
          delete localStorage['icon-idea-' + tile_name];
        }
      }
    }
}
function cleanUpOldTiles() {
  var values = Object.values(localStorage),
       keys = Object.keys(localStorage),
       i = keys.length;
    while ( i-- ) {
      if (keys[i].startsWith('lastShown-') && !keys[i].startsWith('lastShown-idea-')) {
        var tile_name = keys[i].substring('lastShown-'.length);
        var difference = Math.floor(Date.now() / 1000) - parseInt(localStorage[keys[i]]);
        if (difference > (86400 * 7)) {
          console.log('Dropping tile: ' + keys[i]);
          delete localStorage[keys[i]];
          delete localStorage['icon-' + tile_name];
        }
      }
    }
}
window.setTimeout(function () { cleanUpOldTilesIdeas(); cleanUpOldTiles(); }, 3000);
</script>
<script>
if (window.chrome.embeddedSearch.newTabPage.isIncognito)
{
  document.getElementById('add-button').style.display='none';
}
</script>
</body>
</html>
